package com.sgb.kjwl.view.ui.activity.enterprise;

import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.google.android.material.tabs.TabLayout;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityPublishMakeOverBinding;
import com.sgb.kjwl.interfaces.PublishRecyclerClick;
import com.sgb.kjwl.model.entity.enterprise.CompanyPublishEntity;
import com.sgb.kjwl.model.entity.enterprise.CopyrightPublishEntity;
import com.sgb.kjwl.model.entity.enterprise.PatentPublishEntity;
import com.sgb.kjwl.model.entity.enterprise.PropertyPublishEntity;
import com.sgb.kjwl.model.entity.enterprise.TrademarkPublishEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.swgk.core.event.EventConstant;
import com.sgb.link.event.LeaseEvent;
import com.sgb.kjwl.view.ui.adapter.enterprise.CompanyPublishAdapter;
import com.sgb.kjwl.view.ui.adapter.enterprise.CopyrightPublishAdapter;
import com.sgb.kjwl.view.ui.adapter.enterprise.PatentPublishAdapter;
import com.sgb.kjwl.view.ui.adapter.enterprise.PropertyPublishAdapter;
import com.sgb.kjwl.view.ui.adapter.enterprise.TrademarkPublishAdapter;
import com.sgb.kjwl.viewmodel.enterprise.PublishViewModel;
import com.swgk.core.dialog.RoundDialog;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.xrecyclerview.XRecyclerView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.HashMap;
import java.util.Map;

public class MakeOverPublishMainActivity extends AppActivity {

    ActivityPublishMakeOverBinding mBinding;
    PublishViewModel mViewModel;
    private int tradeDataPage = 1;
    private int copyrightDataPage = 1;
    private int patentDataPage = 1;
    private int propertyDataPage = 1;
    private int companyDataPage = 1;
    private boolean isLoadMoreForTrade;
    private boolean isLoadMoreForCopyright;
    private boolean isLoadMoreForPatent;
    private boolean isLoadMoreForProperty;
    private boolean isLoadMoreForCompany;
    private TrademarkPublishAdapter mTrademarkPublishAdapter;
    private CompanyPublishAdapter mCompanyPublishAdapter;
    private CopyrightPublishAdapter mCopyrightPublishAdapter;
    private PropertyPublishAdapter mPropertyPublishAdapter;
    private PatentPublishAdapter mPatentPublishAdapter;
    private boolean isFirst = true;
    private int tabPosition = 0;
    private String companyNo = "0";
    private String teamNo = "0";


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if(!EventBus.getDefault().isRegistered(this)){
            EventBus.getDefault().register(this);
        }
        if (SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0) == 1) {
            companyNo = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.COMPANY_NO, "");
        } else if (SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0) == 2) {
            teamNo = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.COMPANY_NO, "");
        }
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_publish_make_over);
        mBinding.setLifecycleOwner(this);
        mViewModel = new ViewModelProvider(this).get(PublishViewModel.class);
        mBinding.actionBarTab.setOnBackClickListener(v -> finish());
        mBinding.tvSearch.setOnClickListener(this);
        mBinding.imageColose.setOnClickListener(this);
        mBinding.llNeedBq.setOnClickListener(this);
        mBinding.llNeedGs.setOnClickListener(this);
        mBinding.llNeedSb.setOnClickListener(this);
        mBinding.llNeedZc.setOnClickListener(this);
        mBinding.llNeedZl.setOnClickListener(this);
        mBinding.actionBarTab.setTab("商标转让", "专利转让", "版权转让");
        mBinding.actionBarTab.setMenuFunctionClick(v -> {
            mBinding.actionBarTab.setVisibility(View.GONE);
            mBinding.rlAddlayout.setVisibility(View.VISIBLE);
            mBinding.successView.setVisibility(View.GONE);
        });
        initAdapter();
        initListener();
        initObserve();
        mViewModel.setTableData();
    }



    @Override
    protected void onResume() {
        super.onResume();
        Log.e("下标_onResume",getIntent().getIntExtra("position",0)+"");
        searchString(mBinding.actionBarTab.getTabPosition(), false);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
    @Subscribe(threadMode = ThreadMode.MAIN,sticky = true)
    public void onEvent(LeaseEvent event){
        if (event.getMessageTag() == EventConstant.EVENT_CREATE_NEWMAKEOVERDATA) {
            mBinding.actionBarTab.setTabSelet(Integer.parseInt(event.getObject()+""));
        }
    }

    @Override
    public void onMultiClick(View v) {
        super.onMultiClick(v);
        switch (v.getId()) {
            case R.id.tv_search:
                searchString(mBinding.actionBarTab.getTabPosition(), false);
                break;
            case R.id.image_colose:
                setVisibleOrGone(-1);
                break;
            case R.id.ll_need_sb:
                setVisibleOrGone(1);
                break;
            case R.id.ll_need_zl:
                setVisibleOrGone(2);
                break;
            case R.id.ll_need_bq:
                setVisibleOrGone(3);
                break;
            case R.id.ll_need_gs:
                setVisibleOrGone(4);
                break;
            case R.id.ll_need_zc:
                setVisibleOrGone(5);
                break;
        }
    }

    private void initListener() {
        int position = getIntent().getIntExtra("position", 0);
        mBinding.actionBarTab.setTabSelet(position);
        mBinding.actionBarTab.setSelectTab(tab -> {
            switch (tab.getPosition()) {
                case 0:
                    mBinding.cetSearch.setHint("输入搜索商标名称");
                    mBinding.cetSearch.setText("");
                    mBinding.xrvMakeOverPublishMain.setAdapter(mTrademarkPublishAdapter);
                    mBinding.xrvMakeOverPublishMain.setNoMore(false);
                    tradeDataPage = 1;
                    loadTradeData(false);
                    break;
                case 1:
                    mBinding.cetSearch.setHint("输入搜索专利名称");
                    mBinding.cetSearch.setText("");
                    mBinding.xrvMakeOverPublishMain.setAdapter(mPatentPublishAdapter);
                    mBinding.xrvMakeOverPublishMain.setNoMore(false);
                    patentDataPage = 1;
                    loadPatentData(false);
                    break;
                case 2:
                    mBinding.cetSearch.setHint("输入搜索版权名称");
                    mBinding.cetSearch.setText("");
                    mBinding.xrvMakeOverPublishMain.setAdapter(mCopyrightPublishAdapter);
                    mBinding.xrvMakeOverPublishMain.setNoMore(false);
                    copyrightDataPage = 1;
                    loadCopyrightData(false);
                    break;
                case 3:
                    mBinding.cetSearch.setHint("输入搜索资产名称");
                    mBinding.cetSearch.setText("");
                    mBinding.xrvMakeOverPublishMain.setAdapter(mPropertyPublishAdapter);
                    mBinding.xrvMakeOverPublishMain.setNoMore(false);
                    companyDataPage = 1;
                    loadPropertyData(false);
                    break;
                case 4:
                    mBinding.cetSearch.setHint("输入搜索公司名称");
                    mBinding.cetSearch.setText("");
                    mBinding.xrvMakeOverPublishMain.setAdapter(mCompanyPublishAdapter);
                    mBinding.xrvMakeOverPublishMain.setNoMore(false);
                    propertyDataPage = 1;
                    loadCompanyData(false);
                    break;
            }
        });

        mBinding.cetSearch.OnClickSearch(() -> {
            searchString(mBinding.actionBarTab.getTabPosition(), false);
        });

        mBinding.xrvMakeOverPublishMain.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                searchString(mBinding.actionBarTab.getTabPosition(), false);
            }

            @Override
            public void onLoadMore() {
                searchString(mBinding.actionBarTab.getTabPosition(), true);
            }
        });

        //tab选中事件
        mBinding.tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                mViewModel.setPayStatus(tab.getPosition());
                if (isFirst) {
                    isFirst = false;
                } else {
                    tabPosition = tab.getPosition();
                    searchString(mBinding.actionBarTab.getTabPosition(), false);
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    private void initAdapter() {
        mBinding.xrvMakeOverPublishMain.setLayoutManager(new LinearLayoutManager(this));
        mTrademarkPublishAdapter = new TrademarkPublishAdapter(this, null);
        mCopyrightPublishAdapter = new CopyrightPublishAdapter(this, null);
        mCompanyPublishAdapter = new CompanyPublishAdapter(this, null);
        mPatentPublishAdapter = new PatentPublishAdapter(this, null);
        mPropertyPublishAdapter = new PropertyPublishAdapter(this, null);
        mBinding.xrvMakeOverPublishMain.setAdapter(mTrademarkPublishAdapter);
        mTrademarkPublishAdapter.setmPublishEntityPublishRecyclerClick(new PublishRecyclerClick<TrademarkPublishEntity>() {
            @Override
            public void recyclerClick(TrademarkPublishEntity trademarkPublishEntity) {
                new RoundDialog.Builder(MakeOverPublishMainActivity.this)
                        .title("温馨提示")
                        .content(trademarkPublishEntity.getStatus() == 1 ? "是否确认下架？" : "是否确认上架？")
                        .cancel("取消")
                        .confirm("确定")
                        .contentGravity(Gravity.CENTER)
                        .cancelable(false)
                        .confirmCallback(v -> {
                            mViewModel.changeStateMakeoverPublish(MakeOverPublishMainActivity.this, trademarkPublishEntity.getId(), 1, trademarkPublishEntity.getStatus() == 1 ? "0" : "1");
                        })
                        .show();
            }
        });

        mCopyrightPublishAdapter.setmPublishEntityPublishRecyclerClick(new PublishRecyclerClick<CopyrightPublishEntity>() {
            @Override
            public void recyclerClick(CopyrightPublishEntity trademarkPublishEntity) {
                new RoundDialog.Builder(MakeOverPublishMainActivity.this)
                        .title("温馨提示")
                        .content(trademarkPublishEntity.getStatus() == 1 ? "是否确认下架？" : "是否确认上架？")
                        .cancel("取消")
                        .confirm("确定")
                        .contentGravity(Gravity.CENTER)
                        .cancelable(false)
                        .confirmCallback(v -> {
                            mViewModel.changeStateMakeoverPublish(MakeOverPublishMainActivity.this, trademarkPublishEntity.getId(), 3, trademarkPublishEntity.getStatus() == 1 ? "0" : "1");
                        })
                        .show();
            }
        });

        mCompanyPublishAdapter.setmPublishEntityPublishRecyclerClick(new PublishRecyclerClick<CompanyPublishEntity>() {
            @Override
            public void recyclerClick(CompanyPublishEntity trademarkPublishEntity) {
                new RoundDialog.Builder(MakeOverPublishMainActivity.this)
                        .title("温馨提示")
                        .content(trademarkPublishEntity.getStatus() == 1 ? "是否确认下架？" : "是否确认上架？")
                        .cancel("取消")
                        .confirm("确定")
                        .contentGravity(Gravity.CENTER)
                        .cancelable(false)
                        .confirmCallback(v -> {
                            mViewModel.changeStateMakeoverPublish(MakeOverPublishMainActivity.this, trademarkPublishEntity.getId(), 4, trademarkPublishEntity.getStatus() == 1 ? "0" : "1");
                        })
                        .show();
            }
        });

        mPatentPublishAdapter.setmPublishEntityPublishRecyclerClick(new PublishRecyclerClick<PatentPublishEntity>() {
            @Override
            public void recyclerClick(PatentPublishEntity trademarkPublishEntity) {
                new RoundDialog.Builder(MakeOverPublishMainActivity.this)
                        .title("温馨提示")
                        .content(trademarkPublishEntity.getStatus() == 1 ? "是否确认下架？" : "是否确认上架？")
                        .cancel("取消")
                        .confirm("确定")
                        .contentGravity(Gravity.CENTER)
                        .cancelable(false)
                        .confirmCallback(v -> {
                            mViewModel.changeStateMakeoverPublish(MakeOverPublishMainActivity.this, trademarkPublishEntity.getId(), 2, trademarkPublishEntity.getStatus() == 1 ? "0" : "1");
                        })
                        .show();
            }
        });

        mPropertyPublishAdapter.setmPublishEntityPublishRecyclerClick(new PublishRecyclerClick<PropertyPublishEntity>() {
            @Override
            public void recyclerClick(PropertyPublishEntity trademarkPublishEntity) {
                new RoundDialog.Builder(MakeOverPublishMainActivity.this)
                        .title("温馨提示")
                        .content(trademarkPublishEntity.getStatus() == 1 ? "是否确认下架？" : "是否确认上架？")
                        .cancel("取消")
                        .confirm("确定")
                        .contentGravity(Gravity.CENTER)
                        .cancelable(false)
                        .confirmCallback(v -> {
                            mViewModel.changeStateMakeoverPublish(MakeOverPublishMainActivity.this, trademarkPublishEntity.getId(), 5, trademarkPublishEntity.getStatus() == 1 ? "-1" : "1");
                        })
                        .show();
            }
        });

        mTrademarkPublishAdapter.setOnItemClick(new AdapterOnItemClick<TrademarkPublishEntity>() {
            @Override
            public void onItemClick(TrademarkPublishEntity trademarkPublishEntity, int position) {
                ActivityJump.jumpToActivity(MakeOverPublishMainActivity.this, MakeoverPublishDetailActivity.class, Pair.create("type", 0), Pair.create("id", trademarkPublishEntity.getId()));
            }
        });

        mPatentPublishAdapter.setOnItemClick(new AdapterOnItemClick<PatentPublishEntity>() {
            @Override
            public void onItemClick(PatentPublishEntity trademarkPublishEntity, int position) {
                ActivityJump.jumpToActivity(MakeOverPublishMainActivity.this, MakeoverPublishDetailActivity.class, Pair.create("type", 1), Pair.create("id", trademarkPublishEntity.getId()));
            }
        });

        mCopyrightPublishAdapter.setOnItemClick(new AdapterOnItemClick<CopyrightPublishEntity>() {
            @Override
            public void onItemClick(CopyrightPublishEntity trademarkPublishEntity, int position) {
                ActivityJump.jumpToActivity(MakeOverPublishMainActivity.this, MakeoverPublishDetailActivity.class, Pair.create("type", 2), Pair.create("id", trademarkPublishEntity.getId()));
            }
        });

        mPropertyPublishAdapter.setOnItemClick(new AdapterOnItemClick<PropertyPublishEntity>() {
            @Override
            public void onItemClick(PropertyPublishEntity trademarkPublishEntity, int position) {
                ActivityJump.jumpToActivity(MakeOverPublishMainActivity.this, MakeoverPublishDetailActivity.class, Pair.create("type", 3), Pair.create("id", trademarkPublishEntity.getId()));
            }
        });

        mCompanyPublishAdapter.setOnItemClick(new AdapterOnItemClick<CompanyPublishEntity>() {
            @Override
            public void onItemClick(CompanyPublishEntity trademarkPublishEntity, int position) {
                ActivityJump.jumpToActivity(MakeOverPublishMainActivity.this, MakeoverPublishDetailActivity.class, Pair.create("type", 4), Pair.create("id", trademarkPublishEntity.getId()));
            }
        });
    }

    private void initObserve() {
        mViewModel.tableName.observe(this, strings -> {
            for (int i = 0; i < strings.size(); i++) {
                TabLayout.Tab tab = mBinding.tabLayout.newTab();
                tab.setText(strings.get(i));
                mBinding.tabLayout.addTab(tab);
            }
        });
//        loadTradeData(false);
        mViewModel.trademarkListLiveData.observe(this, trademarkPublishEntities -> {
            mBinding.xrvMakeOverPublishMain.refreshComplete();
            if (isLoadMoreForTrade) {
                if (null != trademarkPublishEntities && trademarkPublishEntities.size() > 0) {
                    mBinding.xrvMakeOverPublishMain.loadMoreComplete();
                    mTrademarkPublishAdapter.addDatas(trademarkPublishEntities);
                } else {
                    mBinding.xrvMakeOverPublishMain.setNoMore(true);
                }
                mBinding.xrvMakeOverPublishMain.setVisibility(View.VISIBLE);
            } else {
                mBinding.xrvMakeOverPublishMain.refreshComplete();
                if (null != trademarkPublishEntities && trademarkPublishEntities.size() > 0) {
                    mBinding.xrvMakeOverPublishMain.setVisibility(View.VISIBLE);
                    mBinding.rlNoPublish.setVisibility(View.GONE);
                    mBinding.errorView.setVisibility(View.GONE);
                    mBinding.llList.setVisibility(View.VISIBLE);
                    mTrademarkPublishAdapter.setDatas(trademarkPublishEntities);
                    mBinding.xrvMakeOverPublishMain.setLoadingMoreEnabled(true);
                    if (trademarkPublishEntities.size() < 20)
                        mBinding.xrvMakeOverPublishMain.setNoMore(true);
                } else {
                    mTrademarkPublishAdapter.setDatas(null);
                    mBinding.xrvMakeOverPublishMain.setVisibility(View.GONE);
                    /*if (mBinding.cetSearch.getText().toString().equals("") && 0 == tabPosition) {
                        mBinding.noDataTv.setText("无商标转让发布的记录哦");
                        mBinding.rlNoPublish.setVisibility(View.VISIBLE);
                        mBinding.llList.setVisibility(View.GONE);
                    } else {*/
                        mBinding.rlNoPublish.setVisibility(View.GONE);
                        mBinding.llList.setVisibility(View.VISIBLE);
                        mBinding.errorView.setVisibility(View.VISIBLE);
//                    }
                }
            }
        });

        mViewModel.copyrightListLiveData.observe(this, copyrightPublishEntities -> {
            mBinding.xrvMakeOverPublishMain.refreshComplete();
            if (isLoadMoreForCopyright) {
                if (null != copyrightPublishEntities && copyrightPublishEntities.size() > 0) {
                    mBinding.xrvMakeOverPublishMain.loadMoreComplete();
                    mCopyrightPublishAdapter.addDatas(copyrightPublishEntities);
                } else {
                    mBinding.xrvMakeOverPublishMain.setNoMore(true);
                }
                mBinding.xrvMakeOverPublishMain.setVisibility(View.VISIBLE);
            } else {
                mBinding.xrvMakeOverPublishMain.refreshComplete();
                if (null != copyrightPublishEntities && copyrightPublishEntities.size() > 0) {
                    mBinding.xrvMakeOverPublishMain.setVisibility(View.VISIBLE);
                    mBinding.rlNoPublish.setVisibility(View.GONE);
                    mBinding.errorView.setVisibility(View.GONE);
                    mBinding.llList.setVisibility(View.VISIBLE);
                    mCopyrightPublishAdapter.setDatas(copyrightPublishEntities);
                    mBinding.xrvMakeOverPublishMain.setLoadingMoreEnabled(true);
                    if (copyrightPublishEntities.size() < 20)
                        mBinding.xrvMakeOverPublishMain.setNoMore(true);
                } else {
                    mCopyrightPublishAdapter.setDatas(null);
                    mBinding.xrvMakeOverPublishMain.setVisibility(View.GONE);
                    /*if (mBinding.cetSearch.getText().toString().equals("") && 0 == tabPosition) {
                        mBinding.noDataTv.setText("无版权转让发布的记录哦");
                        mBinding.rlNoPublish.setVisibility(View.VISIBLE);
                        mBinding.llList.setVisibility(View.GONE);
                    } else {*/
                        mBinding.rlNoPublish.setVisibility(View.GONE);
                        mBinding.llList.setVisibility(View.VISIBLE);
                        mBinding.errorView.setVisibility(View.VISIBLE);
//                    }
                }
            }
        });

        mViewModel.patentListLiveData.observe(this, patentPublishEntities -> {
            mBinding.xrvMakeOverPublishMain.refreshComplete();
            if (isLoadMoreForPatent) {
                if (null != patentPublishEntities && patentPublishEntities.size() > 0) {
                    mBinding.xrvMakeOverPublishMain.loadMoreComplete();
                    mPatentPublishAdapter.addDatas(patentPublishEntities);
                } else {
                    mBinding.xrvMakeOverPublishMain.setNoMore(true);
                }
                mBinding.xrvMakeOverPublishMain.setVisibility(View.VISIBLE);
            } else {
                mBinding.xrvMakeOverPublishMain.refreshComplete();
                if (null != patentPublishEntities && patentPublishEntities.size() > 0) {
                    mBinding.xrvMakeOverPublishMain.setVisibility(View.VISIBLE);
                    mBinding.rlNoPublish.setVisibility(View.GONE);
                    mBinding.errorView.setVisibility(View.GONE);
                    mBinding.llList.setVisibility(View.VISIBLE);
                    mPatentPublishAdapter.setDatas(patentPublishEntities);
                    mBinding.xrvMakeOverPublishMain.setLoadingMoreEnabled(true);
                    if (patentPublishEntities.size() < 20)
                        mBinding.xrvMakeOverPublishMain.setNoMore(true);
                } else {
                    mPatentPublishAdapter.setDatas(null);
                    mBinding.xrvMakeOverPublishMain.setVisibility(View.GONE);
                   /* if (mBinding.cetSearch.getText().toString().equals("") && 0 == tabPosition) {
                        mBinding.noDataTv.setText("无专利转让发布的记录哦");
                        mBinding.rlNoPublish.setVisibility(View.VISIBLE);
                        mBinding.llList.setVisibility(View.GONE);
                    } else {*/
                        mBinding.rlNoPublish.setVisibility(View.GONE);
                        mBinding.llList.setVisibility(View.VISIBLE);
                        mBinding.errorView.setVisibility(View.VISIBLE);
//                    }
                }
            }
        });

        mViewModel.propertyListLiveData.observe(this, propertyPublishEntities -> {
            mBinding.xrvMakeOverPublishMain.refreshComplete();
            if (isLoadMoreForProperty) {
                if (null != propertyPublishEntities && propertyPublishEntities.size() > 0) {
                    mBinding.xrvMakeOverPublishMain.loadMoreComplete();
                    mPropertyPublishAdapter.addDatas(propertyPublishEntities);
                } else {
                    mBinding.xrvMakeOverPublishMain.setNoMore(true);
                }
                mBinding.xrvMakeOverPublishMain.setVisibility(View.VISIBLE);
            } else {
                mBinding.xrvMakeOverPublishMain.refreshComplete();
                if (null != propertyPublishEntities && propertyPublishEntities.size() > 0) {
                    mBinding.xrvMakeOverPublishMain.setVisibility(View.VISIBLE);
                    mBinding.rlNoPublish.setVisibility(View.GONE);
                    mBinding.errorView.setVisibility(View.GONE);
                    mBinding.llList.setVisibility(View.VISIBLE);
                    mPropertyPublishAdapter.setDatas(propertyPublishEntities);
                    mBinding.xrvMakeOverPublishMain.setLoadingMoreEnabled(true);
                    if (propertyPublishEntities.size() < 20)
                        mBinding.xrvMakeOverPublishMain.setNoMore(true);
                } else {
                    mPropertyPublishAdapter.setDatas(null);
                    mBinding.xrvMakeOverPublishMain.setVisibility(View.GONE);
                  /*  if (mBinding.cetSearch.getText().toString().equals("") && 0 == tabPosition) {
                        mBinding.noDataTv.setText("无资产转让发布的记录哦");
                        mBinding.rlNoPublish.setVisibility(View.VISIBLE);
                        mBinding.llList.setVisibility(View.GONE);
                    } else {*/
                        mBinding.rlNoPublish.setVisibility(View.GONE);
                        mBinding.llList.setVisibility(View.VISIBLE);
                        mBinding.errorView.setVisibility(View.VISIBLE);
//                    }
                }
            }
        });

        mViewModel.companyListLiveData.observe(this, companyPublishEntities -> {
            mBinding.xrvMakeOverPublishMain.refreshComplete();
            if (isLoadMoreForCompany) {
                if (null != companyPublishEntities && companyPublishEntities.size() > 0) {
                    mBinding.xrvMakeOverPublishMain.loadMoreComplete();
                    mCompanyPublishAdapter.addDatas(companyPublishEntities);
                } else {
                    mBinding.xrvMakeOverPublishMain.setNoMore(true);
                }
                mBinding.xrvMakeOverPublishMain.setVisibility(View.VISIBLE);
            } else {
                mBinding.xrvMakeOverPublishMain.refreshComplete();
                if (null != companyPublishEntities && companyPublishEntities.size() > 0) {
                    mBinding.xrvMakeOverPublishMain.setVisibility(View.VISIBLE);
                    mBinding.rlNoPublish.setVisibility(View.GONE);
                    mBinding.errorView.setVisibility(View.GONE);
                    mBinding.llList.setVisibility(View.VISIBLE);
                    mCompanyPublishAdapter.setDatas(companyPublishEntities);
                    mBinding.xrvMakeOverPublishMain.setLoadingMoreEnabled(true);
                    if (companyPublishEntities.size() < 20)
                        mBinding.xrvMakeOverPublishMain.setNoMore(true);
                } else {
                    mCompanyPublishAdapter.setDatas(null);
                    mBinding.xrvMakeOverPublishMain.setVisibility(View.GONE);
                    if (mBinding.cetSearch.getText().toString().equals("") && 0 == tabPosition) {
                        mBinding.noDataTv.setText("无公司转让发布的记录哦");
                        mBinding.rlNoPublish.setVisibility(View.VISIBLE);
                        mBinding.llList.setVisibility(View.GONE);
                    } else {
                        mBinding.rlNoPublish.setVisibility(View.GONE);
                        mBinding.llList.setVisibility(View.VISIBLE);
                        mBinding.errorView.setVisibility(View.VISIBLE);
                    }
                }
            }
        });

        mViewModel.mChangeSuccess.observe(this, aBoolean -> {
            if (aBoolean) {
                searchString(mBinding.actionBarTab.getTabPosition(), false);
            } else {
                MToast.showToast(this, "操作失败");
            }
        });
    }

    /**
     * 页面跳转 及显示隐藏
     *
     * @param position
     */
    private void setVisibleOrGone(int position) {
        if (-1 != position)
            ActivityJump.jumpToActivity(MakeOverPublishMainActivity.this, MakeOverPublishActivity.class, Pair.create("type", position));
        mBinding.rlAddlayout.setVisibility(View.GONE);
        mBinding.actionBarTab.setVisibility(View.VISIBLE);
        mBinding.successView.setVisibility(View.VISIBLE);
    }

    /**
     * 搜索列表
     *
     * @param actionBarPosition
     * @param isLodeMore
     */
    private void searchString(int actionBarPosition, boolean isLodeMore) {
        switch (actionBarPosition) {
            case 0:
                loadTradeData(isLodeMore);
                break;
            case 1:
                loadPatentData(isLodeMore);
                break;
            case 2:
                loadCopyrightData(isLodeMore);
                break;
            case 3:
                loadPropertyData(isLodeMore);
                break;
            case 4:
                loadCompanyData(isLodeMore);
                break;
        }
    }

    private void loadTradeData(boolean isLoadMore) {
        /**
         page: 1
         limit: 20
         name:
         publishType: 1
         companyNo: 1371363333982261248
         */
        isLoadMoreForTrade = isLoadMore;
        Map<String, Object> map = new HashMap<>();
        map.put("page", isLoadMore ? tradeDataPage += 1 : 1);
        map.put("limit", 20);
        map.put("name", mBinding.cetSearch.getText().toString());
        map.put("publishType", SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0));
        map.put("companyNo", companyNo);
        map.put("teamNo", teamNo);
        mViewModel.getMakeOverPublishTradeList(this, map);
    }

    private void loadCopyrightData(boolean isLoadMore) {
        isLoadMoreForCopyright = isLoadMore;
        Map<String, Object> map = new HashMap<>();
        map.put("page", isLoadMore ? copyrightDataPage += 1 : 1);
        map.put("limit", 20);
        map.put("name", mBinding.cetSearch.getText().toString());
        map.put("publishType", SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0));
        map.put("companyNo", companyNo);
        map.put("teamNo", teamNo);
        mViewModel.getMakeOverPublishCopyrightList(this, map);
    }

    private void loadPatentData(boolean isLoadMore) {
        isLoadMoreForPatent = isLoadMore;
        Map<String, Object> map = new HashMap<>();
        map.put("page", isLoadMore ? patentDataPage += 1 : 1);
        map.put("limit", 20);
        map.put("name", mBinding.cetSearch.getText().toString());
        map.put("publishType", SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0));
        map.put("companyNo", companyNo);
        map.put("teamNo", teamNo);
        mViewModel.getMakeOverPublishPatentList(this, map);
    }

    private void loadPropertyData(boolean isLoadMore) {
        isLoadMoreForProperty = isLoadMore;
        Map<String, Object> map = new HashMap<>();
        map.put("pageSize", isLoadMore ? propertyDataPage += 1 : 1);
        map.put("limit", 20);
        map.put("name", mBinding.cetSearch.getText().toString());
        map.put("publishType", SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0));
        map.put("companyNo", companyNo);
        map.put("teamNo", teamNo);
        mViewModel.getMakeOverPublishPropertyList(this, map);
    }

    private void loadCompanyData(boolean isLoadMore) {
        /**
         * comNo: "1371363333982261248"
         * limit: 20
         * name: ""
         * page: 1
         * searchSource: 2
         * userType: 1
         */
        isLoadMoreForCompany = isLoadMore;
        Map<String, Object> map = new HashMap<>();
        map.put("page", isLoadMore ? companyDataPage += 1 : 1);
        map.put("limit", 20);
        map.put("name", mBinding.cetSearch.getText().toString());
        map.put("userType", SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0));
        map.put("comNo", companyNo);
        map.put("teamNo", teamNo);
        mViewModel.getMakeOverPublishCompanyList(this, map);
    }
}
